Skip to content

feat: add source-map support for editor DOM mapping#347

Merged
MarioCadenas merged 6 commits into
mainfrom
fjakobs/react-sourcemaps
May 20, 2026
Merged

feat: add source-map support for editor DOM mapping#347
MarioCadenas merged 6 commits into
mainfrom
fjakobs/react-sourcemaps

Conversation

@fjakobs
Copy link
Copy Markdown
Collaborator

@fjakobs fjakobs commented May 5, 2026

Summary

  • Added vite-plugin-react-source-loc.ts — a Vite plugin that injects data-source="<file>:<line>:<col>" attributes onto native JSX elements, enabling the editor to map DOM elements back to source locations
  • Enabled sourcemap: true in the Vite build config
  • Added @babel/parser, @babel/traverse, and magic-string as devDependencies

Backported from the app-builder template (universe/apps/app-builder/standalone/packages/app-under-dev).

Test plan

  • Verify databricks apps init produces a working template
  • Verify built client output includes sourcemaps
  • Verify data-source attributes appear on native DOM elements in dev mode

This pull request and its description were written by Isaac.

dev mode

image

prod mode

image

Backport the react-source-loc Vite plugin from the app-builder
template. The plugin injects `data-source="<file>:<line>:<col>"`
attributes onto native JSX elements so the editor can map DOM
elements back to their source location. Also enables `sourcemap: true`
in the Vite build config.

Co-authored-by: Isaac
@fjakobs fjakobs requested a review from a team as a code owner May 5, 2026 17:06
@fjakobs fjakobs requested review from MarioCadenas and pkosiec May 5, 2026 17:06
@MarioCadenas
Copy link
Copy Markdown
Collaborator

general question, should we add this only on dev and not production builds?

Register the data-source injection plugin from ViteDevServer so all
AppKit apps get editor DOM mapping in dev without a template-local
babel plugin. Reimplement with @ast-grep/napi and drop template deps.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Resolve package.json by keeping magic-string alongside main's get-port
and js-yaml deps; regenerate pnpm-lock.yaml.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
… plugin

When Vite root is the app root (not client/src/app/frontend), use
config.root as projectRoot so data-source paths stay inside the app.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Comment thread template/client/vite.config.ts
Comment thread template/client/vite.config.ts Outdated
Avoid shipping source map files in production client builds while
keeping them when NODE_ENV is development.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Copy link
Copy Markdown
Member

@pkosiec pkosiec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

ViteDevServer already resolves the app cwd; pass it into
reactSourceLocPlugin instead of duplicating nested client dir
heuristics that could drift from findClientRoot() candidates.

Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
@MarioCadenas MarioCadenas enabled auto-merge (squash) May 20, 2026 07:56
@MarioCadenas MarioCadenas merged commit 0d595c2 into main May 20, 2026
9 checks passed
@MarioCadenas MarioCadenas deleted the fjakobs/react-sourcemaps branch May 20, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants